##
# This file is part of the Metasploit Framework and may be subject to 
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/framework/
##

require 'rex/proto/http'
require 'msf/core'


class Metasploit3 < Msf::Auxiliary

	include Msf::Exploit::Remote::HttpClient
	include Msf::Auxiliary::WMAPScanDir
	include Msf::Auxiliary::Scanner

	def initialize(info = {})
		super(update_info(info,	
			'Name'   		=> 'Nikto External Module',
			'Description'	=> %q{
				This module launch a nikto session  directory 
				in a given directory path.					
			},
			'Author' 		=> [ 'daniele.bellucci [at] gmail.com' ],
			'License'		=> BSD_LICENSE,
			'Version'		=> '$Revision:$'))   
			
		register_options(
			[
				OptString.new('PATH', [ true,  "The path to identify directoy listing", '/']),
                                OptString.new('NIKTO_PATH', [true, "The nikto full path", '/nikto/nikto.pl' ]),
                                OptString.new('NIKTO_OPTS', [false, "The nikto options to use", '' ])
			], self.class)	
						
	end

	def wmap_enabled
            true
	end


	def run_host(ip)
	
		tpath = datastore['PATH'] 	
		if tpath[-1,1] != '/'
			tpath += '/'
		end 	

                nikto = datastore['NIKTO_PATH']

		if not nikto
			print_error("The nikto script could not be found")
			return
		end

                nikto_url  = (datastore['SSL'] ? "https" : "http")
                nikto_url += "://" + wmap_target_host + ":" + wmap_target_port
                nikto_url += "/" + datastore['PATH'] + '/'
          
                nikto_config = nikto.split('/')[0..-2].join('/')
                
                cmd  = nikto + ' -config=' + nikto_config + '/nikto.conf ' + datastore['NIKTO_OPTS']
                cmd += (datastore['SSL'] ? " -ssl" : "") + ' -host ' + nikto_url
          
                print_status("exec: #{cmd}")
                IO.popen( cmd ) do |io|
                        io.each_line do |line|
                                print_line("NIKTO: " + line)
                        end
		end
	end
end
